package cn.pconline.autoclub.util.ubb.node;

import cn.pconline.autoclub.util.ubb.EscapeUtils;
import cn.pconline.autoclub.util.ubb.Node;

/**
 * 与bokecc.com合作的解析节点，他们的代码为[cc][/cc]
 * @author LiFeng
 */
public class CCNode extends AbstractNode {

	public CCNode() {}

	private CCNode(String name, String attribute) {
		super.name = name;
		super.attribute = attribute;
	}

	@Override
	public StringBuilder getText(java.util.LinkedList<Node> stack) {
		String url = "http://union.bokecc.com/" + text;
		String width = "500";
		String height = "400";

		if (attribute != null) {
			String[] wh = attribute.split("[x|\\,]");
			if (wh.length == 2) {
				width  = wh[0];
				height = wh[1];
			}
		}

		StringBuilder sb = new StringBuilder();
		sb.append("<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" id=\"VideoPlayer\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0\" width=\"").append(width).append("\" height=\"").append(height).append("\" />\n");
		sb.append("<param name=\"movie\" value=\"").append(url).append("\" />\n");
		sb.append("<param name=\"quality\" value=\"high\" />\n");
		sb.append("<param name=\"allowScriptAccess\" value=\"always\" />\n");
		sb.append("<param name=\"allowFullScreen\" value=\"true\" />\n");
		sb.append("<embed name=\"VideoPlayer\" src=\"").append(url).append("\" allowScriptAccess=\"always\" quality=\"high\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" allowfullscreen=\"true\" height=\"").append(height).append("\" width=\"").append(width).append("\" />\n");
		sb.append("</object>");
		return sb;
	}

	@Override
	public void appendText(CharSequence text) {
		EscapeUtils.appendAttribute(text, super.text);
	}

	@Override
	public Node copyWithoutText() {
		return new CCNode(name, attribute);
	}

	@Override
	public Node build(String name, String attribute) {
		return new CCNode(name, attribute);
	}

}
